#!/bin/bash
if ! npm list -g | grep -q doctoc; then
	npm install -g doctoc
fi

TEMP_DIR=$(mktemp -d)

cp README.md $TEMP_DIR/
doctoc $TEMP_DIR

diff -q README.md $TEMP_DIR/README.md
DIFF_RESULT=$?
rm -fr $TEMP_DIR

if [[ $DIFF_RESULT != 0 ]]; then
	echo "doc formatting is invalid. run make fix_format"
	exit 1
fi
